import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { accPanelData } from 'src/data/acc_manage/acc_panel_data';
import { AccManageConst } from "src/consts/acc_manage_const";
import { OrganizationConst } from "src/consts/organization_const";
@Component({})
export default class AccAddPanel extends MyVue {
    name: string = 'AccAddPanel';
    formData: any;
    footerFlag: boolean = true;
    feature_code: String

    initData(that?: any): void {
        WLCommit(AccManageConst.CommitAdd, {})
        that.formData = WLStore().state.accManageAdd;
        that.formData.status = "qiyong"
        that.formData.sex = "man"
        that.feature_code = Config.featureCode + 'account.entity.Account'
    }

    mounted(): void {
    }

    openOrg(): void {
        WLCommit(OrganizationConst.CommitType, "acc")
        let sendData: any = {}
        sendData["curr_page"] = 1
        sendData["page_size"] = 15
        sendData.level = 0
        WLDispatch(OrganizationConst.GetOrgTreeData, sendData);
    }

    addAcc(): void {
        this.formData.isContinue = false
        this.$refs.accAddForm.validate((valid: Boolean) => {
            if (valid) {
                if (isNoEmpty(this.formData.role_list)) {
                    for (let i = 0; i < this.formData.role_list.length; i++) {
                        for (let k in this.formData.role_list[i]) {
                            if (k != "id") {
                                delete this.formData.role_list[i][k]
                            }
                        }
                    }

                    if (isNoEmpty(this.formData.dept_list)) {
                        for (let i = 0; i < this.formData.dept_list.length; i++) {
                            for (let k in this.formData.dept_list[i]) {
                                if (k != "id") {
                                    delete this.formData.dept_list[i][k]
                                }
                            }
                        }
                    }

                    WLDispatch(AccManageConst.DispatchAdd, this.formData);
                }
            } else {
                WLMessage("必填字段为空,无法新增账号", "warning")
                return false;
            }
        })

    }

    continueAddAcc(): void {
        this.formData.isContinue = true
        this.$refs.accAddForm.validate((valid: Boolean) => {
            if (valid) {
                if (isNoEmpty(this.formData.role_list)) {
                    for (let i = 0; i < this.formData.role_list.length; i++) {
                        for (let k in this.formData.role_list[i]) {
                            if (k != "id") {
                                delete this.formData.role_list[i][k]
                            }
                        }
                    }

                    if (isNoEmpty(this.formData.dept_list)) {
                        for (let i = 0; i < this.formData.dept_list.length; i++) {
                            for (let k in this.formData.dept_list[i]) {
                                if (k != "id") {
                                    delete this.formData.dept_list[i][k]
                                }
                            }
                        }
                    }

                    WLDispatch(AccManageConst.DispatchAdd, this.formData);
                }
            } else {
                WLMessage("必填字段为空,无法新增账号", "warning")
                return false;
            }
        })

        setTimeout(() => {
            this.$refs.accAddForm.resetFields();
        }, 500);
    }
}